home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / SAT 2.3a1 / OffscreenToys SAT / SAT_OT.p < prev   
Encoding:
Text File  |  1994-11-09  |  11.1 KB  |  251 lines  |  [TEXT/PJMM]

  1. unit SAT_OT;
  2.  
  3. interface
  4. {$ifc UNDEFINED THINK_PASCAL}
  5.     uses
  6.         Types, QuickDraw; {}
  7. {$endc}
  8.  
  9.     type
  10.         {BMPtr = ^BitMap;}
  11.  
  12.         FacePtr = ^Face;
  13.         Face = record
  14.                 colorData: Ptr;
  15.                 resNum: integer;
  16.                 iconMask: BitMap;
  17.                 rowBytes: integer;
  18.                 next: FacePtr;
  19.                 maskRgn: RgnHandle;
  20.             end;
  21.  
  22.         SpritePtr = ^Sprite;
  23.         Sprite = record
  24. { Variables that you should change as appropriate }
  25.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  26.                 position: Point;
  27.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  28.                                         {hotRect is set by you. hotRect2 is offset to the current position.}
  29.                 face: FacePtr; { Pointer to the Face (appearance) to be used. }
  30.                 task: ProcPtr; { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  31.                 hitTask: ProcPtr; { Callback in collisions. }
  32.                 destructTask: ProcPtr; { Called when a sprite is disposed. (Usually nil.) }
  33.                 clip: RgnHandle; {Clip region to be used when this sprite is drawn.}
  34. { SAT variables that you shouldn't change: }
  35.                 oldpos: Point;                {The 'task' routine is not allowed to change this! }
  36.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  37.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  38.                 oldFace: FacePtr;            {Used by RunSAT2}
  39.                 dirty: Boolean;            {Used by RunSAT2}
  40. {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
  41. {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
  42. {after initializing (before any sprites are created)!}
  43.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  44.                 speed: Point; { Can be used for speed, but not necessarily. }
  45.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  46.                 fixedPos: Point; {Fixed-point position}
  47.                 appLong: Longint; {Longint for free use by the application.}
  48.             end;
  49.  
  50. {Type for SATs pattern utilities.}
  51.     type
  52.         SATPattern = record
  53.                 patternType: integer; {1 = Pattern, PatHandle, 2 = PixPat, PixPatHandle}
  54.                 thePat: PixPatHandle; {or PatHandle}
  55.             end; {record}
  56.         SATPatPtr = ^SATPattern;
  57.         SATPatHandle = ^SATPatPtr;
  58.  
  59. {Update list. Used internally}
  60.         UpdatePtr = ^UpdateRec;
  61.         UpdateRec = record
  62.                 updateRect: Rect;
  63.                 next: UpdatePtr;
  64.             end;
  65.  
  66. {The globals record. Some fields are important for you. These are marked with *}
  67.         SATglobalsRec = record
  68.                 wind: WindowPtr;                            {*The window that SAT draws in. }
  69.                 offSizeH, offSizeV: integer;                    {*Offscreen size, used to limit sprite positions}
  70.                 offScreen: GrafPtr;                            {*Offscreen image }
  71.                 backScreen: GrafPtr;                        {*Background image }
  72.                 offScreenGD, backScreenGD: GDHandle;    {GDevices for offScreen and backScreen.}
  73.  
  74.                 ox, oy: longint;                                {Internal}
  75.                 pict, bwpict: integer;                        {PICT id's}
  76.                 fitThePICTs: boolean;                        {Resize PICTs to fit?}
  77.                 sorting: integer;                                {Chosen sorting}
  78.                 collision: integer;                            {Chosen collision handling}
  79.                 searchWidth: integer;                        {Chosen search width}
  80.                 device: GDHandle;                            {Chosen screen}
  81.                 screen: PixMapHandle;                        {Internal}
  82.                 bounds: Rect;                                    {Internal}
  83.                 initDepth: Integer;                            {*Depth at last icon initialization}
  84.                 synchHook: ProcPtr;                            {Synch procedure}
  85.                 sRoot: SpritePtr;                                {Sprite list root}
  86.                 updateRoot: UpdatePtr;                        {Update list root}
  87.                 anyMonsters: Boolean;                        {*False when no sprites with kind < -1 are active }
  88.  
  89.                 ditherOff: CGrafPtr;                            {Internal}
  90.                 ditherOffGD: GDHandle;                        {Internal}
  91.                 iconPort: CGrafPtr;                            {Internal}
  92.                 iconPortGD: GDHandle;                        {Internal}
  93.                 iconPort2: CGrafPtr;                        {Internal}
  94.                 iconPort2GD: GDHandle;                        {Internal}
  95.                 bwIconPort: GrafPtr;                         {Internal}
  96. {Environment-independent globals:}
  97.                 faceRoot: FacePtr;                    {Root of face list}
  98.                 colorFlag: Boolean;                    {True if color QuickDraw is available.}
  99.             end;
  100.  
  101. {Configuration types: VPositionSort and KindCollision are defaults.}
  102.     const
  103. {Sorting options}
  104.         kVPositionSort = 0;
  105.         kLayerSort = 1;
  106.         kNoSort = 2;
  107. {Collision detection options}
  108.         kKindCollision = 0;
  109.         kForwardCollision = 1;
  110.         kBackwardCollision = 2;
  111.         kNoCollision = 3;
  112.         kForwardOneCollision = 4;
  113.  
  114.     var
  115. {$ifc UNDEFINED THINK_PASCAL}
  116.         gSAT: SATglobalsRec;
  117.         external;                {Most globals in a record. See above.}
  118.         gSATSoundErrorProc: ProcPtr;
  119.         external;        {Pointer to procedure to call on sound error.}
  120. {$elsec}
  121. {$J+}
  122.         gSAT: SATglobalsRec;                {Most globals in a record. See above.}
  123.         gSATSoundErrorProc: ProcPtr;        {Pointer to procedure to call on sound error.}
  124. {$J-}
  125. {$endc}
  126.  
  127. {Initializing and customizing}
  128.     procedure SATConfigure (PICTfit: boolean; newSorting, newCollision, searchWidth: integer);
  129.     procedure SATInit (pictID, bwpictID, Xsize, Ysize: integer);
  130.     procedure SATCustomInit (pictID, bwpictID: integer; SATdrawingArea: Rect; {}
  131.                                     preloadedWind: WindowPtr; chosenScreen: GDHandle; useMenuBar, {}
  132.                                     centerDrawingArea, fillScreen, dither4bit, beSmart: Boolean);
  133. {Maintainance, background manipulation etc.}
  134.     function SATDepthChangeTest: Boolean;
  135.     procedure SATDrawPICTs (pictID, bwpictID: integer);
  136.     procedure SATRedraw;
  137. {Drawing}
  138.     procedure SATPlotFace (theFace: FacePtr; theGrafPtr: GrafPtr; theGDevice: GDHandle;{}
  139.                                     where: Point; fast: boolean);
  140.     procedure SATPlotFaceToScreen (theFace: FacePtr; where: Point; fast: boolean);
  141.     procedure SATCopyBits (src, dest: GrafPtr; destGD: GDHandle; {}
  142.                                     srcRect, destRect: Rect; fast: Boolean);
  143.     procedure SATCopyBitsToScreen (src: GrafPtr; srcRect, destRect: Rect; fast: Boolean);
  144.     procedure SATBackChanged (r: Rect); {Tell SAT about changes in backScreen}
  145. {SetPort replacements}
  146.     procedure SATGetPort (var port: GrafPtr; var device: GDHandle);
  147.     procedure SATSetPort (port: GrafPtr; device: GDHandle);
  148.     procedure SATSetPortOffScreen; {Use before using QuickDraw on offScreen}
  149.     procedure SATSetPortBackScreen; {Use before using QuickDraw on backScreen}
  150.     procedure SATSetPortScreen; {Use to set port to gSAT.wind}
  151. {Basic sprite handling}
  152.     function SATGetFace (resNum: integer): FacePtr;
  153.     procedure SATDisposeFace (theFace: FacePtr);
  154.     function SATNewSprite (kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  155.     function SATNewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  156.     procedure SATKillSprite (who: Spriteptr);
  157. {Animating}
  158.     procedure SATRun (fast: Boolean); {The heart of the whole package!}
  159.     procedure SATRun2 (fast: Boolean); {Alternate routine for allowing resting sprites}
  160. {Special functions for advanced programmers}
  161.     procedure SATInstallSynch (theSynchProc: ProcPtr);
  162.     procedure SATInstallEmergency (theEmergencyProc: ProcPtr);
  163.     procedure SATSetSpriteRecSize (theSize: longint);
  164.     procedure SATSkip;
  165.     procedure SATKill; {Dispose of offscreen buffers to allow re-init}
  166. {Offscreen - use only if you need an *extra* offscreen buffer. These calls are likely to change in the future!}
  167.     procedure SATMakeOffscreen (var portP: GrafPtr; rectP: Rect; var retGDevice: GDHandle); {Make offscreen buffer in current screen depth and CLUT.}
  168.     procedure SATDisposeOffScreen (var portP: GrafPtr; theGDevice: GDHandle); {Get rid of offscreen}
  169.     function CreateOffScreen (bounds: Rect; depth: Integer; colors: CTabHandle; var retPort: CGrafPtr; var retGDevice: GDHandle): OSErr; {From Principia Offscreen - color only}
  170.     procedure DisposeOffScreen (doomedPort: CGrafPtr; doomedGDevice: GDHandle);{From Principia Offscreen - color only}
  171. {Face manipulation (for advanced programmers)}
  172.     procedure SATSetPortMask (theFace: FacePtr);
  173.     procedure SATSetPortFace (theFace: FacePtr);
  174.     procedure SATSetPortFace2 (theFace: FacePtr);
  175.     function SATNewFace (faceBounds: Rect): FacePtr;
  176.     procedure SATChangedFace (theFace: FacePtr);
  177.  
  178. {Old names, kept for compatibility with old programs}
  179. {function GetFace (resNum: integer): FacePtr;}
  180. {procedure DisposeFace (theFace: FacePtr);}
  181. {function NewSprite (kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;}
  182. {function NewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;}
  183. {procedure KillSprite (who: SpritePtr);}
  184. {function NewFace (faceBounds: Rect): FacePtr;}
  185. {procedure ChangedFace (theFace: FacePtr);}
  186. {procedure PeekOffscreen; {Old name for SATRedraw}
  187.  
  188. {New procedures, EXPERIMENTAL, intended for C++ users}
  189.     function SATNewSpritePP (afterthis: SpritePtr; sStorage: Ptr; theKind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  190.     procedure SATCopySprite (destSprite: SpritePtr; srcSprite: SpritePtr);
  191.     function SATNewFacePP (faceBounds: Rect; fStorage: Ptr): FacePtr;
  192.     procedure SATCopyFace (destFace: FacePtr; srcFace: FacePtr);
  193.     procedure SATDisposeFacePP (theFace: FacePtr);
  194.  
  195.  
  196. {Cicn utilities}
  197.     function SATGetCicn (cicnId: integer): CIconHandle;
  198.     procedure SATPlotCicn (theCicn: CIconHandle; dest: GrafPtr; destGD: GDHandle; r: Rect); {Borde jag lägga till device?}
  199.     procedure SATDisposeCicn (theCicn: CIconHandle);
  200.  
  201. {Utilities}
  202.     procedure SATSetStrings (ok, yes, no, quit, memerr, noscreen, nopict, nowind: Str255);
  203.     function SATTrapAvailable (theTrap: Integer): Boolean;
  204.     procedure DrawInt (i: integer);
  205.     procedure DrawLong (l: longint);
  206.     function Rand (n: integer): integer;
  207.     function Rand10: integer;
  208.     function Rand100: integer;
  209.     procedure ReportStr (str: str255);
  210.     function QuestionStr (str: str255): Boolean;
  211.     function SATFakeAlert (s1, s2, s3, s4: Str255; nButtons, defButton, cancelButton: integer;{}
  212.                                     t1, t2, t3: Str255): integer;
  213.     procedure CheckNoMem (p: Ptr); {If the Ptr is nil, out of memory emergency exit}
  214.     procedure SetMouse (where: point);
  215. {Pattern utilities}
  216.     procedure SATPenPat (SATpat: SATPatHandle);
  217.     procedure SATBackPat (SATpat: SATPatHandle);
  218.     function SATGetPat (patID: integer): SATPatHandle;
  219.     procedure SATDisposePat (SATpat: SATPatHandle);
  220. {Menu bar utilities}
  221.     procedure SATShowMBar;
  222.     procedure SATHideMBar (wind: WindowPtr);
  223. {Sound}
  224.     procedure SATSoundInit; {Called from SATInit}
  225.     procedure SATSoundPlay (TheSound: Handle; Priority: integer; CanWait: boolean);
  226.     procedure SATSoundEvents; {Call this once in a while when not calling SATRun often}
  227.     procedure SATSoundShutup; {Silence, dispose of sound channel}
  228.     procedure SATSoundOn;
  229.     procedure SATSoundOff;
  230.     function SATSoundDone: Boolean; {Any sound going on ?}
  231.     function SATGetSound (sndId: integer): handle;        { To load a sound and get a handle for SATSoundPlay }
  232.     function SATGetNamedSound (name: Str255): Handle; { Same but using resource names }
  233.     procedure SATDisposeSound (theSnd: handle);
  234. {Multi-channel sound routines}
  235.     function SATSoundInitChannels (num: integer): integer;
  236.     function SATSoundDoneChannel (chanNum: integer): Boolean;
  237.     procedure SATSoundPlayChannel (theSound: Handle; chanNum: integer);
  238.     procedure SATSoundReserveChannel (chanNum: integer; reserve: Boolean);
  239.     procedure SATSoundShutupChannel (chanNum: integer);
  240.     procedure SATPreloadChannels;
  241. {Experimental, likely to be renamed/removed/changed:}
  242.     procedure SATSoundPlay2 (theSound: Handle; priority: integer; canWait, skipIfSame: Boolean);
  243.     procedure SATSoundPlayEasy (theSound: Handle; canWait: Boolean);
  244. {More multi-channel:}
  245.     function SATGetNumChannels: integer;
  246.     function SATGetChannel (chanNum: integer): Ptr;
  247. {Customization}
  248.     procedure SATSetSoundInitParams (params: Longint);
  249.  
  250. implementation
  251. end.